<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>系统模块管理</title>
		<link rel="stylesheet" href="/static/layui/css/layui.css" />
<link rel="stylesheet" href="/static/ui/css/ui.css" />
	</head>
	<body class="pear-container">
		
		<div class="layui-card">
			<div class="layui-card-body">
				<table id="mod-table" lay-filter="mod-table"></table>
			</div>
		</div>

		<script type="text/html" id="mod-toolbar">
			<button class="layui-btn layui-btn-primary layui-border-red layui-btn-sm" lay-event="add">
		        <i class="layui-icon layui-icon-add-1"></i>
		        新增
		    </button>
			<button class="layui-btn layui-btn-primary layui-border-blue layui-btn-sm" lay-event="param">
		        <i class="layui-icon layui-icon-windows"></i>
		        全局常量
		    </button>
		</script>

		
		<script type="text/html" id="mod-bar">
			<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit">
				<i class="layui-icon layui-icon-edit"></i>
			</button>
			<button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove">
				<i class="layui-icon layui-icon-delete"></i>
			</button>
		</script>
        <script src="../config.js"></script>
		<script src="/static/layui/layui.js"></script>
		<script src="/static/ui/ui.js"></script>
		<script>
			layui.use(['table', 'form', 'jquery','common'], function() {
				let table = layui.table;
				let form = layui.form;
				let $ = layui.jquery;
				let common = layui.common;

				let MODULE_PATH = "./";

				let cols = [
					[{
						title: '名称',
						field: 'name',
						align: 'center'
					}, {
						title: '标志',
						field: 'key',
						align: 'center'
					}, {
						title: '路径',
						field: 'server_path',
						align: 'center'
					}, 
					// {
					// 	title: '类型',
					// 	field: 'typeName',
					// 	align: 'center'
					// }, {
					// 	title: '操作',
					// 	toolbar: '#mod-bar',
					// 	align: 'center'
					// }
					]
				]

				table.render({
					elem: '#mod-table',
					url: apiUrl + 'mod/list',
				    headers: getHeader(),
					page: true,
                    parseData: function (res) {
						//setRoute(res.data.routeData);
						//layui.menu.reload();
                        return {
                            "code": res.code, //解析接口状态
                            "msg": res.message, //解析提示文本
                            "count": res.data.count, //解析数据长度
                            "data": res.data.list //解析数据列表
                        };
                    },
					cols: cols,
					skin: 'line',
					toolbar: '#mod-toolbar',
					defaultToolbar: [{
						title: '刷新',
						layEvent: 'refresh',
						icon: 'layui-icon-refresh',
					}, 'filter', 'print', 'exports']
				});
                table.on('tool(mod-table)', function(obj) {
					if (obj.event === 'remove') {
						window.remove(obj);
					} else if (obj.event === 'edit') {
						window.edit(obj);
					}
				});
				
				window.add = function(obj) {
					layer.open({
						type: 2,
						title: '添加模块',
						offset: 'rt',
                        area: [
                            '80%', '100%'
                        ],
                        anim: 1,
                        maxmin: true,
						content: MODULE_PATH + 'add.html'
					});
				}
                

    
                //类目管理-------------------------------------------//
                
                table.on('toolbar(mod-table)', function(obj) {
					if (obj.event === 'add') {
						window.add();
					} else if (obj.event === 'refresh') {
						window.refresh();
					}
					 else if (obj.event === 'param') {
						window.param();
					}
				});
				
				window.param = function(obj) {
					layer.open({
						type: 2,
						title: '全局常量',
						offset: 'rt',
                        area: [
                            '80%', '100%'
                        ],
                        anim: 1,
                        maxmin: true,
						content: MODULE_PATH + 'param.html'
					});
				}
				window.edit = function(obj) {
					layer.open({
						type: 2,
						title: '修改模块-' + obj.data.name,
						offset: 'rt',
                        area: [
                            '80%', '100%'
                        ],
                        anim: 1,
                        maxmin: true,
						content: MODULE_PATH + 'edit.html?id=' + obj.data.id
					});
				}

				window.remove = function(obj){
		            layer.confirm('确定要删除该模块吗', {icon: 3, title:'提示'}, function(index){
		                layer.close(index);
		                _post(layui, 'mod/delete',{id : obj.data.id}, res => {
							layer.msg('删除成功',{icon:1,time:1000},() => {
								obj.del();
							});
						}, err => {
							//layer.msg('删除失败',{icon:2,time:1000});
						})
		            });
		        }
                //类目管理结束-------------------------------------//

				window.refresh = function(param) {
					table.reload('mod-table');
				}
			})
		</script>
	</body>
</html>
